package cn.tedu.charging.user.dao.repository.impl;

import cn.tedu.charging.user.dao.mapper.UserMapper;
import cn.tedu.charging.user.dao.repository.UserRepository;
import cn.tedu.charging.user.pojo.po.UserPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class UserRepositoryImpl implements UserRepository {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserPO getUserByOpenId(String openId) {
        QueryWrapper<UserPO> queryWrapper = new QueryWrapper<UserPO>();
        queryWrapper.eq("wx_open_id", openId);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public Integer saveUser(String openId, String nickName) {
        UserPO user = new UserPO();
        user.setNickName(nickName);
        user.setWxOpenId(openId);
        //insert 方法返回的是影响行数
        int row = userMapper.insert(user);
        return user.getId();
    }
}
